﻿using System.ComponentModel;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Phone.Tasks;
using WinSource.Model;
using WinSource.Services;

namespace WinSource.ViewModel
{
    public class WritersViewModel : ViewModelBase
    {
        #region Fields

        private readonly DataService _dataService;

        #endregion

        #region Constructor

        public WritersViewModel(DataService dataService)
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                _dataService = dataService;

                WriteEmailCommand = new RelayCommand(WriteEmail);
            }
        }

        #endregion

        #region Properties

        public Writer CurrentWriter { get; set; }
        public Writer WriterJoe { get { return _dataService.WriterJoe; } }
        public Writer WriterAshley { get { return _dataService.WriterAshley; } }
        
        public RelayCommand WriteEmailCommand { get; private set; }

        #endregion

        #region 

        private void WriteEmail()
        {
            try
            {
                EmailComposeTask emailComposeTask = new EmailComposeTask
                {
                    To = CurrentWriter.Email,
                    Subject = string.Format("Contact {0} from WinSource", CurrentWriter.Name)
                };
                emailComposeTask.Show();
            }
            catch
            {
            }
        }

        #endregion
    }
}